﻿using Fabrication.DataSources;

namespace Fabrication.ValueProviders
{
    internal class EmailProvider : ValueProviderBase<string>
    {
        private static readonly int givenNamesMax = HumanNames.GivenNames.Count - 1;
        private static readonly int domainsMax = Email.Domains.Count - 1;
        private static readonly int topLevelDomainsMax = Email.TopLevelDomains.Count - 1;

        protected sealed override string GetValue(object item)
        {
            var givenName = HumanNames.GivenNames[RandomNumberGenerator.GetInteger(0, givenNamesMax)].ToLowerInvariant();
            var domain = Email.Domains[RandomNumberGenerator.GetInteger(0, domainsMax)];
            var topLevelDomain = Email.TopLevelDomains[RandomNumberGenerator.GetInteger(0, topLevelDomainsMax)];
            return string.Format("{0}@{1}.{2}", givenName, domain, topLevelDomain);
        }
    }
}